package be.ipl.diavoloz.modele;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotBlank;

@Entity
@Table(schema = "DIAVOLOZ", name = "JOUEURS")
public class Joueur implements Serializable {

	private static final long serialVersionUID = -6310969563391253933L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int joueur_id;

	@NotBlank
	@NotNull
	@Column(unique = true)
	private String pseudo;

	@NotNull
	@Column(unique = true)
	private String email;

	@NotNull
	private String mdp;

	@NotNull
	private int age;

	@ManyToOne
	private Partie partie;

	protected Joueur() {
	}

	public Joueur(String pseudo, int age, String email, String mdp) {
		this.pseudo = pseudo;
		this.age = age;
		this.email = email;
		this.mdp = mdp;
	}

	public String getPseudo() {
		return pseudo;
	}

	public void setPartie(Partie partie) {
		this.partie = partie;
	}

	public Partie getPartie() {
		return partie;
	}

	public int getAge() {
		return age;
	}

	public String getEmail() {
		return email;
	}

	public String getMdp() {
		return mdp;
	}

	public int getId(){
		return joueur_id;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + age;
		result = prime * result + joueur_id;
		result = prime * result + ((mdp == null) ? 0 : mdp.hashCode());
		result = prime * result + ((partie == null) ? 0 : partie.hashCode());
		result = prime * result + ((pseudo == null) ? 0 : pseudo.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Joueur other = (Joueur) obj;
		if (age != other.age)
			return false;
		if (joueur_id != other.joueur_id)
			return false;
		if (mdp == null) {
			if (other.mdp != null)
				return false;
		} else if (!mdp.equals(other.mdp))
			return false;
		if (partie == null) {
			if (other.partie != null)
				return false;
		} else if (!partie.equals(other.partie))
			return false;
		if (pseudo == null) {
			if (other.pseudo != null)
				return false;
		} else if (!pseudo.equals(other.pseudo))
			return false;
		return true;
	}
}
